/* textstream - a library for rendering scrolling text
 * Copyright (C) 2011 Jack Kelly <jack@jackkelly.name>
 *
 * This library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "textstream_event.h"

struct textstream_event* textstream_text_event_new(const gchar* str,
                                                   gboolean instant) {
  struct textstream_event* ev = g_new(struct textstream_event, 1);
  *ev = (struct textstream_event) {
    .type = TEXTSTREAM_EVENT_TEXT,
    {
      .text = {
        .i = 0,
        .instant = instant,
        .str = g_strdup(str)
      }
    }
  };
  return ev;
}

struct textstream_event* textstream_fg_event_new(F437Color fg) {
  struct textstream_event* ev = g_new(struct textstream_event, 1);
  *ev = (struct textstream_event) {
    .type = TEXTSTREAM_EVENT_FG,
    {
      .fg = fg
    }
  };
  return ev;
}

struct textstream_event* textstream_bg_event_new(F437Color bg) {
  struct textstream_event* ev = g_new(struct textstream_event, 1);
  *ev = (struct textstream_event) {
    .type = TEXTSTREAM_EVENT_BG,
    {
      .bg = bg
    }
  };
  return ev;
}

struct textstream_event* textstream_newline_event_new(void) {
  struct textstream_event* ev = g_new(struct textstream_event, 1);
  *ev = (struct textstream_event) {
    .type = TEXTSTREAM_EVENT_NEWLINE
  };
  return ev;
}

void textstream_event_free(struct textstream_event* ev) {
  switch (ev->type) {
  case TEXTSTREAM_EVENT_TEXT:
    g_free(ev->text.str);
    break;
  case TEXTSTREAM_EVENT_FG:
    break;
  case TEXTSTREAM_EVENT_BG:
    break;
  case TEXTSTREAM_EVENT_NEWLINE:
    break;
  }
  g_free(ev);
}
